package com.inxedu.os.edu.service.main.impl;

import com.inxedu.os.edu.dao.SysUserMapper;
import com.inxedu.os.edu.pojo.SysUser;
import com.inxedu.os.edu.pojo.SysUserExample;
import com.inxedu.os.edu.service.main.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;
    @Override
    public SysUser queryLoginUser(String parameter) {
        SysUserExample example = new SysUserExample();
        SysUserExample.Criteria criteria = example.createCriteria();
        criteria.andLoginNameEqualTo(parameter);
        List<SysUser> sysUsers = sysUserMapper.selectByExample(example);
        if(sysUsers.isEmpty()){
            return null;
        }
        return sysUsers.get(0);
    }

    @Override
    public void updateUserLoginLog(Integer userId, Date date, String s) {
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("userId", userId);
        map.put("time", date);
        map.put("ip", s);
        sysUserMapper.updateUserLoginLog(map);
    }
}
